//
//  MYTabBarController.swift
//  积分商城
//
//  Created by apple on 2016/12/6.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MYTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white

        addChildVc()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }

    private func addChildVc(){
        addChildViewController(vc: MYHomeViewController(), title: "首页", imgName: "v2_home")
        addChildViewController(vc: MYOrderViewController(), title: "超市", imgName: "v2_order")
        addChildViewController(vc: MYShopCarViewController(), title: "购物车", imgName: "shopCart")

        addChildViewController(vc: MYMineViewController(), title: "我的", imgName: "v2_my")

    }

    private func addChildViewController(vc: UIViewController, title: String, imgName: String){
        // 设置 title
        vc.title = title

        //                vc.navigationItem.title = "首页"
        //                vc.tabBarItem.title = "首页"
        // 设置文字颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: UIControlState.selected)
        // 设置图片
        vc.tabBarItem.image = UIImage(named: imgName)
        // 选中的图片(alwaysOriginal 原生渲染方式)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_r")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        // 添加
        let vcNav = UINavigationController(rootViewController: vc)
        vc.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.red]
        addChildViewController(vcNav)
    }


}
